package com.lin.controller.user;


import com.lin.common.result.Result;
import com.lin.entity.DynamicEntity;
import com.lin.entity.User;
import com.lin.entity.dto.UserDto;
import com.lin.entity.vo.UserVo;
import com.lin.service.PersonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 个人主页
 */
@RestController
@RequestMapping("/person")
@Api(tags = "个人主页相关接口")
public class PersonController {

    @Autowired
    private PersonService personService;

    /**
     * 获得用户数据
     * @param userDto
     * @return
     */
    @GetMapping
    @ApiOperation("获得用户数据")
    public Result<UserVo> getDate(@RequestBody UserDto userDto){
        UserVo userVo = personService.getDate(userDto);
        return Result.success(userVo);
    }

    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @PostMapping
    @ApiOperation("修改用户信息")
    public Result update(@RequestBody User user){
        personService.update(user);
        return Result.success();
    }
    /**
     * 获取用户发布动态信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/getDynamic")
    @ApiOperation("获取用户发布动态信息")
    public Result<List<DynamicEntity>> get(Integer userId){
        List<DynamicEntity> dynamicEntity = personService.get(userId);
        return Result.success(dynamicEntity);
    }
}
